﻿/* 14. Write methods to calculate minimum, maximum, average, sum and product of given set of integer numbers. 
 * Use variable number of arguments. */

using System;

public class SeveralCalculationsOnSet
{
    public static int[] array;

    public static void Main()
    {
        array = Common.InputArray(array, "\nExample 1\n----------");
        Console.WriteLine("\nMinimal: {0}\nMaximal: {1}\nSum: {2}\nAverage: {3}\nProduct: {4}\n\n", 
            Minimal(array),
            Maximal(array),
            Sum(array),
            Average(array),
            Product(array));

        Console.WriteLine("Example 2\n----------------\nArray: 2, -5, 20, 9\nAverage: {0}\n\n", Average(2, -5, 20, 9));
    }

    public static int Minimal(params int[] array)
    {
        int min = array[0];

        foreach (int member in array)
            if (member < min)
                min = member;

        return min;
    }

    public static int Maximal(params int[] array)
    {
        int max = array[0];

        foreach (int member in array)
            if (member == Int32.MaxValue)
                return Int32.MaxValue;
            else
            {
                if (max < member)
                    max = member;
            }

        return max;
    }

    public static double Sum(params int[] array)
    {
        double sum = 0;

        foreach (int member in array)
            sum += member;

        return sum;
    }

    public static double Average(params int[] array)
    {
        return 1.0d * Sum(array) / array.Length;
    }

    public static double Product(params int[] array)
    {
        double product = 1.0d;

        foreach (int member in array)
            product *= member;

        return product;
    }
}